<template>
  <div class="tab-index" >
    <div class="head">
      <div class="search">
        <van-search v-model="searchText" placeholder="keyword" />
      </div>
    </div>
    <div class="content">
      <div class="column">
        <div ref="col1">
          <div
            class="item"
            v-for="(item, index) in data1"
            :key="index"
            @click.stop="gotoDetail(item)"
          >
            <div class="pro">
              <img
                v-if="item.pictureList.length"
                :src="item.pictureList[0].url"
                alt=""
              />
            </div>

            <div class="des">
              <div class="title">
                {{ item.content }}
              </div>
              <div class="bottom">
                <div class="avator">
                  <img src="https://img.fcgbox.com/heads/4.webp" alt="" />

                  <span class="name">{{ item.title }}</span>
                </div>
                <div class="like">
                  <!-- 55<svg class="icon svg-icon icon-like" aria-hidden="true">
                <use xlink:href="#anticon-like"></use>
              </svg> -->
                  <span class="icon iconfont">&#xe7c8;</span
                  ><span class="count">{{ item.likeCount }}</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="column">
        <div ref="col2">
          <div
            class="item"
            v-for="(item, index) in data2"
            :key="index"
            @click.stop="gotoDetail(item)"
          >
            <div class="pro">
              <img
                v-if="item.pictureList.length"
                :src="item.pictureList[0].url"
                alt=""
              />
            </div>

            <div class="des">
              <div class="title">
                {{ item.content }}
              </div>
              <div class="bottom">
                <div class="avator">
                  <img src="https://img.fcgbox.com/heads/4.webp" alt="" />

                  <span class="name">{{ item.title }}</span>
                </div>
                <div class="like">
                  <!-- 55<svg class="icon svg-icon icon-like" aria-hidden="true">
                <use xlink:href="#anticon-like"></use>
              </svg> -->
                  <span class="icon iconfont">&#xe7c8;</span
                  ><span class="count">{{ item.likeCount }}</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
  
  <script>

export default {
  name: "tab-index",
  data() {
    return {
      
      searchText: "",
      data1: [],
      data2: [],
    };
  },
  

  mounted() {
    this.getData();
    console.log(this.bgColor);
  },
  methods: {
    remove(data) {
      return new Promise((resolve) => {
        this.$nextTick(() => {
          data.splice(0, 1);

          resolve(true);
        });
      });
    },
    gotoDetail(item) {
      this.$router.push({
        name: "unboxingDetail",
        query: {
          id: item.id,
        },
      });
    },
    getData() {
      this._showLoading();
      this.$http
        .get(`api/v1/reviews`)
        .then(async (res) => {
          this._dismissLoading();
          if (res.data && res.data.isSuccess) {
            while (res.data.resultData.length) {
              
              if (
                this.$refs.col1.offsetHeight <= this.$refs.col2.offsetHeight
              ) {
                this.data1.push(res.data.resultData[0]);
              } else {
                this.data2.push(res.data.resultData[0]);
              }
              await this.remove(res.data.resultData);
              console.log(res.data.resultData.length);
            }
          }
        })
        .catch((err) => {
          this._dismissLoading();
          this._showToast(err.message);
        });
    },
  },
};
</script>
  
  <style scoped lang="scss">
.van-nav-bar {
  // background: var(--bg-color);
}
.tab-index {
  // background: var(--bg-color);
  .head {
    position: fixed;
    height: 57px;
    background: var(--main-bc-color);

    width: 100%;
    .search {
      padding: 10px 12px;
      .van-search {
        width: 310px;
        height: 37px;
        margin-right: auto;
        background: var(--reviewSearchBgColor) !important;
        padding: 0 5px;
        box-sizing: border-box;
        display: flex;
        justify-content: flex-start;
        align-items: center;

        .van-search__content {
          background: var(--reviewSearchBgColor) !important;
        }
      }
    }
  }
  .content {
    margin-top: 57px;
    display: flex;
    .column {
      width: 50%;
    }

    .item {
      width: calc(100% - 2px);
      text-align: center;
      // float: left;

      .pro {
        background: var(--item-bc);
        img {
          width: calc(100% - 4px);
        }
      }
      .des {
        background: var(--item-bc);
        .title {
          width: 100%;
          margin: 0x 0px 5px 0;
          padding: 5px 0px 0px 0;
          box-sizing: border-box;
          /* padding: 5px 10px; */
          box-sizing: border-box;
          color: var(--color);
          /* height: 33px; */
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          font-size: 19px;
          -webkit-box-orient: vertical;
          overflow: hidden;
          display: -webkit-box;
          text-overflow: ellipsis;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
        }
        .bottom {
          display: flex;
          justify-content: space-between;
          .avator {
            img {
              width: 26px;
              height: 26px;
              border-radius: 50%;
              vertical-align: middle;
              margin: 0 5px 0 10px;
            }
            font-size: 16px;
            font-weight: 400;
            margin-right: auto;
            color: var(--color);
          }
          .like {
            color: rgb(96, 98, 102);
            line-height: 24px;
            padding-right: 10px;
            .count {
              padding-left: 5px;
              font-size: 12px;
            }
          }
        }
      }
    }
  }
}
</style>
<style   lang="less">
.tab-index {
  .van-field__left-icon .van-icon {
    color: rgb(121, 121, 121) !important;
  }
  .search {
    input {
      color: var(--color);
    }
  }
}
</style>
  